import requests
import logging

baseUrl = 'http://md.dev.jingjianx.vip'


def login():
    requestData = {'userName': '18664702135', 'password': '123456'}
    response = requests.post(baseUrl + '/basic/manager/login/account', json=requestData)
    assert response.status_code == 200
    responseData = response.json()
    token = responseData['data']['token']
    return token


# 登录成功
def test_login_account_success():
    # 请求
    requestData = {'userName': '18664702135', 'password': '123456'}
    response = requests.post(baseUrl + '/basic/manager/login/account', json=requestData)

    # 验证
    assert response.status_code == 200
    responseData = response.json()
    assert responseData['success'] == True


# 登录失败
def test_login_account_failure():
    # 请求
    requestData = {'userName': '18664702135', 'password': '000000'}
    response = requests.post(baseUrl + '/basic/manager/login/account', json=requestData)

    # 验证
    assert response.status_code == 200

    responseData = response.json()
    assert responseData['success'] == False


def test_getEntryExitState_summary():
    token = login()
    # 请求
    headers = {
        'Authorization': 'Bearer ' + token,
    }
    response = requests.get(baseUrl + '/device/cashier/machine/entryexitstate/summary', headers=headers)
    assert response.status_code == 200
    responseData = response.json()
    assert responseData['success'] == True


def test_basic_manager_login_weixin_refresh():
    requestData = {
        'uid': '01_042833A0CBBB497484746DCC434A8DFA'
    }
    response = requests.post(baseUrl + '/basic/manager/login/weixin/refresh', json=requestData)
    assert response.status_code == 200
    responseData = response.json()
    assert responseData['success'] == True